﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Example.Objects1;
using Example.Objects2;

namespace Example.Mappers.Tests
{
    [TestClass]
    public class AddressMapperTest
    {
        [TestMethod]
        public void MapTo_Address2From_Address1_ReturnsEquivalent()
        {
            var srcAddress = CreateAddress1();

            var dstAddress = srcAddress.ToAddress2();

            CustomAssert.AreEquivalent(srcAddress, dstAddress);
        }

        [TestMethod]
        public void MapFrom_Address2ToNewAddress1_InjectsEquivalent()
        {
            var srcAddress = CreateAddress2();

            var dstAddress = new Address1().From(srcAddress);

            CustomAssert.AreEquivalent(srcAddress, dstAddress);
        }

        [TestMethod]
        [ExpectedException(typeof(NullReferenceException))]
        public void MapFrom_Address2ToNullAddress1_ThrowsException()
        {
            var srcAddress = CreateAddress2();
            
            Address1 dstAddress = null;
            dstAddress = dstAddress.From(srcAddress);
        }

        public static Address1 CreateAddress1()
        {
            return new Address1()
            {
                Country = new KeyValuePair<int,string>(33, "France"),
                City = "Paris",
                Street = new Street1()
                {
                    Name = "rue Clerc",
                    Number = "7 ter"
                }
            };
        }
        public static Address2 CreateAddress2()
        {
            return new Address2()
            {
                Country = new KeyValuePair<CountryCode, string>(CountryCode.USA, "USA"),
                City = "New York",
                Street = new Street2()
                {
                    Name = "Broadway",
                    Number = "55"
                }
            };
        }
    }
}
